package com.cxhc.system.service.cockpit.impl;

import com.cxhc.common.utils.StringUtils;
import com.cxhc.system.mapper.cockpit.SysEntMapper;
import com.cxhc.system.service.cockpit.ISysEntService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysEntserviceImpl implements ISysEntService {


    @Autowired
    private SysEntMapper sysEntMapper;

    @Override
    public int selectEntByDate(String date) {
       return sysEntMapper.countEnt(date);
    }

    @Override
    public Map<String,String> selectEntByType(String date) {
        //获取企业总数
        Map<String,String> mapRes = new HashMap<>();
        List<Map<String, Object>> maps = sysEntMapper.countEntByType(date);
        for (Map<String, Object> map : maps) {
            BigDecimal typeCount = new BigDecimal(String.valueOf(map.get("typeCount")));
            String industry = (String)map.get("industry");
            if (StringUtils.isEmpty(industry)){
                industry = "其他";
            }
            if (BigDecimal.ZERO.equals(typeCount)){
                mapRes.put(industry, "0");
            }else {
                mapRes.put(industry,typeCount.toString());
            }
        }
        return mapRes;
    }

    @Override
    public Map<String, Map<String, Object>> queryByFloor(String date) {
        Map<String, Map<String,Object>> entMaps = sysEntMapper.countEntByFloor(date);
        Map<String, Map<String,Object>> userMaps = sysEntMapper.countUserByFloor(date);

        for (String areaId : entMaps.keySet()) {
            Map<String, Object> resutMap = entMaps.get(areaId);
            resutMap.put("userCount",userMaps.get(areaId).get("userCount"));
        }
        return entMaps;
    }
}
